﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class MaterialConfig : POBaseConfig<MaterialPO>
    {
        public override void InitializeData(EntityTypeBuilder<MaterialPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<MaterialPO> builder, ref int index)
        {
            builder.HasComment("物料表");
            builder.Property(entity => entity.Code).ConfigColumn("CODE", "编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Name).ConfigColumn("NAME", "名称", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TypeCode).ConfigColumn("TYPE_CODE", "类型编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Length).ConfigColumn("LENGTH", "长").HasColumnOrder(index++);
            builder.Property(entity => entity.Width).ConfigColumn("WIDTH", "宽").HasColumnOrder(index++);
            builder.Property(entity => entity.Height).ConfigColumn("HEIGHT", "高").HasColumnOrder(index++);
            builder.Property(entity => entity.Weight).ConfigColumn("WEIGHT", "重量").HasColumnOrder(index++);
            builder.Property(entity => entity.FillQuantity).ConfigColumn("FILL_QUANTITY", "满盘数量").HasColumnOrder(index++);
            builder.Property(entity => entity.ColumnCount).ConfigColumn("COLUMN_COUNT", "托盘列数").HasColumnOrder(index++);
            builder.Property(entity => entity.ReworkLimit).ConfigColumn("REWORK_LIMIT", "返修上限").HasColumnOrder(index++);
            builder.Property(entity => entity.BindBarcode).ConfigColumn("BIND_BARCODE", "绑定识别码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
        }

        public override void MapIndex(EntityTypeBuilder<MaterialPO> builder)
        {
            builder.HasIndex(entity => new { entity.Code, entity.BindBarcode, entity.WarehouseCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();
            builder.HasIndex(entity => new { entity.BindBarcode, entity.WarehouseCode }).HasDatabaseName($"UN_{TableName}_2").IsUnique();
        }
    }
}
